/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$(document).ready(function() {
    $("#changeForm").validate({
            rules: {
	             name: {
                      required:true,
                      minlength:6,
                      maxlength:50
                  },// simple rule, converted to {required:true}
	          email: {// compound rule
	          required: true,
	          email: true
	        },
                password:{
                    required:true,
                    minlength:5,
                    maxlength:20
                },
                   // equalTo: "#newPassword"
               // },
                newpassword:{
                    required : function()
                  {
                    return false;
                  },
                    minlength:5 ,
                    maxlength:10
                },
                confirmPassword:{
                    equalTo: "#newPassword"
                },
                credit:{
                 required : true,
                 min: 0,
                 max: 1000000
                },
	        phone:{
                    number:true,
                    minlength:10,
                    maxlength:10
                }
                }
               });

    $("#loginForm").validate({
        rules: {
            userName:{
                      email:true,
                      required:true
                      
            },
            password:{
                      required:true,
                      minlength:5,
                      maxlength:20
                     }
                }
               });

	      $("#signupForm").validate({
	        rules: {
	          name: {
                      required:true,
                      minlength:6,
                      maxlength:50
                  },// simple rule, converted to {required:true}
	          email: {// compound rule
	          required: true,
	          email: true
	        },
                password:{
                    required:true,
                    minlength:5,
                    maxlength:20
                },
                confirmpassword:{
                    equalTo: "#password"
                },
                credit:{
                 required : true,
                 min: 0,
                 max: 1000000
                },
	        phone:{
                    number:true,
                    minlength:10,
                    maxlength:10
                }
                }
	      });
});
function signinShowBox()
 {
     $("#loginMainBox").css("display","block");
     $("#loginMainBox").css("z-index","3");
     $("#main_container").append("<img  id='backimage' src='style/images/background.jpg' style='width:100%;height:150%;left:0px;top:0px;z-index:2;position:absolute;opacity:0.8;' />");
 }
 function closeSignin()
 {
    $("#loginMainBox").css("display","none");
    $("#loginMainBox").css("z-index","0");
    $("#backimage").remove();
    $("#Errorfont").remove();
 }
function submitLoginForm()
{
    $("#loginForm").submit();
}
function submitChangeForm()
{
    if($("#changeForm").valid())
        {
             if(checkPassword())
                 {
                    $("#changeForm").submit();
                 }
                 else
                     {
                         $("#changePassword").append("<label for='textPassword' generated='true' class='error'>Enter valid password</label>");
                     }
        }
}
function checkPassword()
{
    if(($("#newPassword").val() == "") && ($("#oldPassword").val() == ""))
                         {
                            return true;
                         }
                      else
                          {
                              if(($("#oldPassword").val() != "") && ($("#oldPassword").val()==$("#hiddenPassword").val()))
                                  {
                                    if($("#newPassword").val() != "")
                                        {
                                            $("#hiddenPassword").val($("#newPassword").val());
                                            return true;
                                        }
                                   else
                                       {
                                   return false;
                                       }
                                  }
                                  else
                                      {
                                          return false;
                                      }
                          }

}